package com.study.javaOther.permission.handle;

import com.study.javaOther.permission.accoperation.IACCOperation;
import com.study.javaOther.permission.entity.Acc;
import com.study.javaOther.permission.enums.PermissionEnum;

import java.util.LinkedList;
import java.util.List;

/**
 * @Name: ConditionDto
 * @Description: java类作用描述
 * @Author: yn
 * @CreateDate: 2022/4/20 14:36
 * @Remark: 特殊说明
 * @Version: 1.0
 */
public class ConditionHandle extends Acc implements IAccHandle {
    private List<IAccHandle> children = new LinkedList<>();
    public ConditionHandle(List<IAccHandle> children){
        this.children=children;
    }
    @Override
    public Boolean check(PermissionEnum permission) {
        IACCOperation iaccOperation = convertOperation(getOperation());
        if (iaccOperation.match(getLeft(),getRight())) {
            for (IAccHandle child : children) {
                Boolean check = child.check(permission);
                if (check!=null) {
                    return check;
                }
            }
        }
        return null;
    }
}
